package com.weilai.service.serviceImpl;

import com.weilai.controller.exceptionHandler.BusinessException;
import com.weilai.controller.exceptionHandler.Code;
import com.weilai.dao.LikesDao;
import com.weilai.dao.PostsDao;
import com.weilai.domain.Likes;
import com.weilai.service.LikesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LikesServiceImpl implements LikesService {

    @Autowired
    private LikesDao likesDao;
    @Autowired
    private PostsDao postsDao;

    //根据用户id查询点赞的文章...
    @Override
    public List<Likes> getLikesByUserId(int userId) {
        return likesDao.getLikesByUserId(userId);
    }

    // 按 userid 删除点赞信息
    @Override
    public void deleteUserById(int userId){
        try {
            likesDao.deleteUserById(userId);
        } catch (Exception e) {
            throw new BusinessException(Code.SYSTEM_DB_ERROR, "按id删除用户信息时数据库出错");
        }
    }

//    @Override
//    public int countUserLiked(int userId, int postId) {
//        int i = postsDao.countUserLiked(userId, postId);
//        if(i==1){
//            //点赞了
//            return 1;
//        }else if(i==0){
//            //没有点赞
//            return 0;
//        }else{
//            throw new BusinessException(Code.PROJECT_BUSINESS_ERROR,"点赞异常");
//        }
//
//    }
}
